/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package amd.core.extraction;

import amd.core.data.ListTermFrequency;
import amd.core.data.TermFrequency;
import amd.core.*;

/**
 *
 * @author Latifah Dwi Nurachma
 */
public class Stemmer {
    public static ListTermFrequency stemming(ListTermFrequency terms){
        int i = 0;
        ListTermFrequency newTerm = new ListTermFrequency();
        while (i<terms.size()){
            String stringForStemmed = terms.get(i).getContent();
            int freq = terms.get(i).getFrequency();
            stringForStemmed = stemOneWord(stringForStemmed);
            if(!stringForStemmed.isEmpty()){
                newTerm.add(new TermFrequency(stringForStemmed, freq));
            }
            i++;
        }
        return newTerm;
    }

    public static String stemOneWord(String stringInput){
        PorterStemmer ps = new PorterStemmer(stringInput);
        ps.stem();
        stringInput = ps.toString();
        return stringInput;
    }
}
